package com.sunose.agfmk.utils;

import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;

import com.sunose.agfmk.constant.Constant;

import java.io.BufferedInputStream;

/**
 * Created by  William Wang on 2013-0903 下午4:38.
 * open asserts directory file
 */
public class fileUtils {
    public final static String tag=Constant.TAG_PREFIX+"_fileUtils";
    static fileUtils instance=null;
    static Context context=null;

    //private singole patter
    private fileUtils()
    {};
    public static fileUtils getInstance(Context cont)
    {
      if(context==null)context=cont;
      if(instance==null)instance=new fileUtils();
        return instance;
    }
    public Bitmap readFile(String filename,String folder) throws Exception
    {
       AssetManager mngr=context.getAssets();
        String name=folder+"/"+filename;
        Log.v(tag, name);
        BufferedInputStream buf = new BufferedInputStream(mngr.open(name));
        Bitmap bitmap = BitmapFactory.decodeStream(buf);
        buf.close();
        return bitmap;
    }

}
